package com.matrix.java.chap_05;

import java.util.Scanner;

/*
    统计：计算平均值和标准方差
 */
public class Ex5_45 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter ten numbers: ");
        int count = 0;
        double sum = 0;
        double squareSum = 0;
        double avg;
        double variance;
        do {
            double number = input.nextDouble();
            sum += number;
            squareSum += Math.pow(number, 2);
            count++;
        } while (count != 10);
        avg = sum / count;
        variance = Math.pow((squareSum - (Math.pow(sum, 2) / count)) / (count - 1), 0.5);
        System.out.printf("%s%.2f%n", "The mean is ", avg);
        System.out.printf("%s%.5f%n", "The standard deviation is ", variance);
        input.close();
    }
}
